<template>
	<view class="container">
		<!-- {{detailsObj.photoList}} -->

		<swiperVue :flag="swiperFlag" :images="detailsObj.photoList" :data="swiperList" @current="getCheckSwiper">
		</swiperVue>
		<!-- 标题-->
		<view class="header">
			<!-- 颜色遮罩层 -->
			<view class="back"></view>
			<view class="introduction">
				<view class="title">
					{{detailsObj.goodsname}}
				</view>
				<view class="address_box">
					<view class="address">
						景区电话：10086
					</view>
					<view class="orange">
						拨打
						<uni-icons type="right" color="orangered" size="15"></uni-icons>
					</view>
				</view>
				<view class="address_box">
					<view class="address">
						{{detailsObj.address}}
					</view>
					<view class="orange">
						地图
						<uni-icons type="right" color="orangered" size="15"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="body">
			<!-- 门票抢购 -->
			<view class="body_box admission_fee">
				<view class="body_title">
					<view></view>门票抢购11
				</view>
				<template v-for="(v,i) in detailsObj.skuList">
					<!-- {{v}} -->
					<admissionVue :data="v" @openPopup="openFun"></admissionVue>
				</template>

			</view>
			<!-- 景区速览 -->
			<view class="body_box scanning_scenic">
				<view class="body_title">
					<view></view>景区速览
				</view>
				<view class="scanning">
					<!-- {{showText}} -->
					<rich-text :class="showText?'content_scanning':'content_scanning_not'" :nodes="detailsObj.detail"
						preview="true"></rich-text>
					<view class="scanning_down" v-if="showText" @click="handleFload">
						展开更多
						<uni-icons type="down" size="20" color="#3d81ff"></uni-icons>
					</view>
					<view class="scanning_up" v-if="!showText" @click="handleFload">
						收起更多
						<uni-icons type="up" size="20" color="#3d81ff"></uni-icons>
					</view>
				</view>
			</view>
			<!-- 开放时间 -->
			<view class="body_box ">
				<view class="body_title">
					<view></view>开放时间
				</view>
				<!-- <template> -->
				<openingHoursVue></openingHoursVue>

				<!-- </template> -->

			</view>
			<!-- 周边美食 -->
			<view class="body_box ">
				<view class="body_title">
					<view></view>周边美食
				</view>

			</view>
		</view>
		<!-- 弹出层 -->
		<uni-popup ref="popup" @click="closeFun" background-color="#fff" @change="change">
			<view class="popup_box" :class="{ 'popup-height': 'left' }">
				<view class="popup_title">
					{{detailsObj.goodsname}}
				</view>
				<view class="popup_body">
					<view  class="detailBoxDiag">
					<view class="blodTitle">门票细则</view>
					<view>1.营业时间：07:30-18:00</view>
					<view>2.预定时间：随时可订；检/换票后不可退!</view>
					<view>3.有效期：120小时有效</view>
					<view>4.门票价格：成人票210元，成人30分钟可用票180元</view>
					<view  class="blodTitle">使用说明</view>
					<view>1.使用方法：出示订单二维码，去窗口采集人脸，刷脸入园</view>
					<view>2.使用时间：08:00 -18:00</view>
					<view class="blodTitle">费用说明</view>
					<view>1.费用包含：婺源景区11个子景点的通票，5日内有效，成人通票一张。</view>
					<view>2.景点包含：游览门票，不含缆车/娱乐设施等费用</view>
					<view class="blodTitle">退票规则：使用后不可退!</view>
					<view class="blodTitle">服务时间：08:00 - 21:00</view>
					<view class="blodTitle">温馨提示：所有景点门票，门票一经使用更换不可退票!</view>
					</view>
				</view>
				<view class="popup_footer">
					<view class="price">
						￥{{skuPrice}}
					</view>
					<view class="btn" @click="toBuy">
						立即购票
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		getCurrentInstance
	} from "vue";
	import {
		onLoad
	} from '@dcloudio/uni-app'
	// 获取商品详情
	import {
		shopDetails
	} from "@/api/index.js"
	import swiperVue from "../../components/IndexSwiper.vue";
	// 门票
	import admissionVue from "../../components/admission.vue";
	import openingHoursVue from "../../pagesC/components/openingHours.vue";
	// 存值
	import {
		setItem,
		getItem
	} from "@/utils/storage.js"
	// pinia存值
	import {
		useLru
	} from "@/hooks/useLru.js"

	const LRU = useLru()
	// 初始化
	LRU.init('goodsDetaillru', 11)

	// 传值id
	const ids = ref('')
	// 定义对象接受接口数据
	let detailsObj = ref({})
	const swiperList = ref([])
	const current = ref(0)
	const swiperDotIndex = ref(0)
	const modeIndex = ref(0)
	const styleIndex = ref(-1)
	const mode = ref('default')
	const dotsStyles = reactive({
		backgroundColor: 'rgba(83, 200, 249,0.3)',
		border: '1px rgba(83, 200, 249,0.3) solid',
		color: '#fff',
		selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',
		selectedBorder: '1px rgba(83, 200, 249,0.9) solid'
	})
	const swiperFlag = ref(false)
	const images = ref([])
	// 文本样式
	const showText = ref(true)
	const showAll = ref(true) //控制展开收起
	// SKUid
	const skuID = ref()
	function change(e) {
		current.value = e.detail.current;
	}

	onLoad((options) => {
		ids.value = options.id
		// console.log(options)

		let lruRes = LRU.findOne('goodsDetaillru', ids.value)
		if (lruRes) {
			detailsObj.value = lruRes.data
			console.log(detailsObj.value)
			detailsObj.value.detail = decodeReplace(detailsObj.value.detail)
		} else {
			getShopList()
		}
	})

	const getShopList = (() => {
		shopDetails({
			id: ids.value
		}).then(res => {
			LRU.set('goodsDetaillru', ids.value, res)
			detailsObj.value = res.data
goodsname.value = res.data.goodsname
			detailsObj.value.detail = decodeReplace(detailsObj.value.detail)
		})
	})
	// 定义弹框
	const popup = ref(null);
	const skuPrice = ref(0)
	const goodsname =ref("")
	const openFun = ((res) => {
		console.log(res, '回调了')
		skuID.value =res.id
		skuPrice.value = res.price
		popup.value.open();
	})

	const closeFun = ((res) => {
		popup.value.close()
	})

	const decodeReplace = (str) => {
		let flag = str.indexOf('amp')
		// text = text.replace('&amp;', '<p').replace('amp;', '')
		if (flag !== -1) {
			str = str.replace(/&amp;/g, '&')
			return decodeReplace(str)
		} else {
			return detailChange(str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(
				/<img/g, `<img width='100%' `).replace(/<p/g, `<p style='display:block' `))
		}
		console.log(str)

	}
	const detailChange = (str) => {
		const regeWidth = /<img[^>]*?style="[^"]*?width:([^;]+);?[^"]*?"[^>]*>/gi;
		str = str.replace(regeWidth, (match, width) => {
			return match.replace(`width:${width};`, 'width:100%;')
		})
		const regeHeight = /<img[^>]*?style="[^"]*?height:([^;]+);?[^"]*?"[^>]*>/gi;
		str = str.replace(regeHeight, (match, width) => {
			return match.replace(`height:${width};`, 'height:auto')
		})
		return str
	}

	function toBuy() {
		uni.navigateTo({
			url: "/pagesD/ticketing/ticketing?ids=" + ids.value+"&skuID="+skuID.value+"&price="+skuPrice.value+"&goodsname="+goodsname.value
		})
	}

	function getCheckSwiper() {

	}



	// 切换显示隐藏
	function handleFload() {

		showText.value = !showText.value
		// console.log(showText, showText.value, 'showAll')
	}
</script>

<style lang="less" scoped>
	.container {
		.background {
			width: 100%;
			height: 600rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.header {
			width: 100%;
			// padding: 0 40rpx;
			box-sizing: border-box;
			// height: 200rpx; //减80
			position: relative;

			.back {
				width: 100%;
				height: 80rpx;
				position: relative;
				top: -80rpx;
				background: linear-gradient(rgba(250, 250, 250, 0), rgba(250, 250, 250));
			}

			.introduction {
				width: 96%;
				// height: 280rpx;
				background: #fff;
				padding: 30rpx;
				margin-left: 2%;
				position: absolute;
				bottom: 0;
				border-radius: 30rpx;
				box-sizing: border-box;
				z-index: 3;

				.title {
					font-weight: 600;
					font-size: 46rpx;
					padding-bottom: 30rpx;
					margin-bottom: 10rpx;
				}

				.address_box {
					display: flex;
					align-items: center;
					// margin-bottom: 10rpx;

					.address {
						flex: 1;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}

					.orange {
						font-size: 24rpx;
						color: orangered;
						padding-left: 10rpx;
					}
				}

				.address_box+.address_box {
					margin-top: 30rpx;
				}

			}
		}

		.body {
			width: 96%;
			margin-left: 2%;

			.body_title {
				font-weight: 600;
				font-size: 46rpx;
				display: flex;
				align-items: flex-end;

				view {
					width: 16rpx;
					height: 50rpx;
					background: linear-gradient(orangered, #fff);
					margin-right: 10rpx;
					border-radius: 20rpx;
				}
			}

			.body_box {
				background: #fff;
				padding: 30rpx;
				border-radius: 30rpx;
				box-sizing: border-box;
				margin-top: 20rpx;
			}

			.admission_fee {}

			.scanning_scenic {
				.scanning {
					padding: 20rpx;
					box-sizing: border-box;
					/* 首行缩进2个字符 */
					// text-indent: 2em;

					position: relative;

					.content_scanning {
						width: 100%;
						height: auto;
						line-height: 50rpx;
						font-size: 34rpx;
						display: -webkit-box;
						/*  CSS 属性 word-break 指定了怎样在单词内断行。 */
						word-break: break-all;
						-webkit-box-orient: vertical;
						/* 要显示多少行就改变line-clamp的数据,此处折叠起来显示3行*/
						-webkit-line-clamp: 9;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.content_scanning_not {
						width: 100%;
						height: auto;
						line-height: 50rpx;
						font-size: 34rpx;

					}

					.scanning_down {
						width: 100%;
						height: 100rpx;
						background: linear-gradient(rgba(0, 0, 0, 0), rgba(250, 250, 250, .9), #fff);
						position: absolute;
						bottom: 0;
						display: flex;
						justify-content: center;
						align-items: flex-end;
						color: #3d81ff;

						.uni-icons {
							text-indent: 0;
						}
					}

					.scanning_up {
						width: 100%;
						height: 60rpx;
						display: flex;
						justify-content: center;
						align-items: flex-end;
						color: #3d81ff;

						.uni-icons {
							text-indent: 0;
						}
					}
				}
			}

		}

		.uni-swiper-dot-box {
			height: 600rpx;
		}

		.swiper-box {
			height: 600rpx;
		}


		.swiper-box {
			height: 100%;
		}

		.swiper-item {
			/* #ifndef APP-NVUE */
			display: flex;
			/* #endif */
			flex-direction: column;
			justify-content: center;
			align-items: center;
			height: 100%;
			color: #fff;
		}

		.swiper-item0 {
			background-color: #cee1fd;
		}

		.swiper-item1 {
			background-color: #b2cef7;
		}

		.swiper-item2 {
			background-color: #cee1fd;
		}

		.image {
			width: 750rpx;
		}
	}

	.uni-popup,
	.uni-popup__wrapper {
		width: 100% !important;
		height: 100% !important;
	}

	@mixin flex {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	@mixin height {
		/* #ifndef APP-NVUE */
		height: 100%;
		/* #endif */
		/* #ifdef APP-NVUE */
		flex: 1;
		/* #endif */
	}

	.box {
	/*	@include flex;*/
	}

	.popup-content {
		/*@include flex;*/
		align-items: center;
		justify-content: center;
		padding: 15px;
		height: 50px;
		background-color: #fff;
	}

	.popup-height {
		/**@include height;*/
		width: 200px;
	}

	.uni-popup .uni-popup__wrapper .popup_box {
		height: 60vh;
		// overflow: auto;
		display: flex;
		flex-direction: column;
		position: fixed;
		bottom: 0;
		left: 0;
		// margin-top: 50vh;
		border-radius: 20rpx 20rpx 0 0;
		width: 100%;
		background: #fff;

		.popup_title {
			border-bottom: 1rpx solid lightgray;
			padding: 20rpx;
			box-sizing: border-box;
			font-size: 36rpx;
			font-weight: 600;
		}

		.popup_body {
			flex: 1;
			width: 100%;
			overflow: auto;
			background: #efefef;
			margin: 0;
		}

		.popup_footer {
			width: 100%;
			height: 100rpx;
			border-top: 1rpx solid lightgray;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0;

			.price {
				color: orangered;
				padding-left: 30rpx;
				font-weight: 600;
				font-size: 34rpx;
			}

			.btn {
				height: 100%;
				width: 220rpx;
				line-height: 100rpx;
				background: linear-gradient(90deg, orangered, orange);
				text-align: center;
				color: #fff;
			}
		}
	}
	.detailBoxDiag{
		background-color: #fff;
		padding: 20rpx;
	}
	.blodTitle{
		font-size: 36rpx;
		font-weight: bold;
		padding: 10rpx 0rpx;
	}
</style>